package com.itheima.dao;

import com.github.pagehelper.Page;
import com.itheima.pojo.Role;
import com.itheima.pojo.User;
import org.apache.ibatis.annotations.*;

import java.util.List;
import java.util.Map;

/**
 * @author ${xinpl}
 * @date 2020/4/13-11:26
 */
public interface UserDao {
    //根据用户名查询用户对象信息  嵌套查询
    User findUserByUsername(String username);
    //根据用户名查询用户对象信息  连表查询
    User findUserByUsername2(String username);

    //curd
    int deleteByPrimaryKey(Integer id);
    int insertSelective(User record);
    User selectByPrimaryKey(Integer id);
    int updateByPrimaryKeySelective(User record);

    //分页
    Page<User> findPage(String queryString);

    @Insert("insert into t_user_role (role_id,user_id) values (#{rid},#{id}) ")
    void setRoleAndUser(Map<String, Integer> map);

    @Select("select role_id from t_user_role where user_id = #{id} ")
    List<Integer> findRoleByUserId(int id);
    @Delete("delete from t_user_role where user_id = #{id}")
    void deleteRoleAndUser(Integer id);

    //根据用户名 获取用户所有角色id
    List<Integer> getRoleByUsername(String username);

    @Update("UPDATE t_user set password = #{pass} where id = #{pid} ")
    void EditPassword(@Param("pid") Integer pid,@Param("pass") String pass);
}
